package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.HisDepartmentEntity;
import io.renren.service.HisDepartmentService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 历史部门表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-05-28 09:44:38
 */
@Controller
@RequestMapping("hisdepartment")
public class HisDepartmentController {
	@Autowired
	private HisDepartmentService hisDepartmentService;
	
	@RequestMapping("/hisdepartment.html")
	public String list(){
		return "hisdepartment/hisdepartment.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("hisdepartment:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		
		//查询列表数据
		List<HisDepartmentEntity> hisDepartmentList = hisDepartmentService.queryList(map);
		int total = hisDepartmentService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(hisDepartmentList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("hisdepartment:info")
	public R info(@PathVariable("id") String id){
		HisDepartmentEntity hisDepartment = hisDepartmentService.queryObject(id);
		
		return R.ok().put("hisDepartment", hisDepartment);
	}
	
	/**
	 * 树形列表
	 */
	@ResponseBody
	@RequestMapping("/treelist")
	public R treelist( String sort, String order, String time) {
		Map<String, Object> map = new HashMap<>();
		String year = null;
		String month = null;
		if (time != null&&time != "") {
			year = time.substring(0,4);
			month = time.substring(5,7);
		}
		map.put("year", year);
		map.put("month", month);
//		if (sort.isEmpty() || sort == null) {
//
//		} else {
//			//map.put("orderby", " order by " + sort + " " + order + " ");
//		}
		// 查询列表数据
		List<HisDepartmentEntity> dictDepartmentList = hisDepartmentService.queryList(map);

		return R.ok().put("list", dictDepartmentList);
	}
	

	

	
}
